	  Subroutine DeviceQuery(nDevices)
	  
      Use Cudafor
    
	  Implicit None
      
      Type (cudaDeviceProp) :: prop
      Integer :: nDevices, i, ierr

!.... Number of CUDA-capable devices

      Ierr = cudaGetDeviceCount(nDevices)
      
      If (ierr /= cudaSuccess) Then
         Write(*,*) 'cudaGetDeviceCount failed -- CUDA driver and runtime may be mismatched'
         Stop
      End If 
      
      If (nDevices == 0) Then
         Call Termination('No CUDA devices found')
      Else If (nDevices == 1) Then
         Write(*,"(/,'One CUDA device found',/)")
      Else 
         Write(*,"(/,I0,' CUDA devices found',/)") nDevices
      End If

!.... Loop over devices
      
      Do i = 0, nDevices-1
          
         Write(*,"('Device Number: ',i0)") i+1 
          
         ierr = cudaGetDeviceProperties(prop, i)
         If (ierr == 0) then
            Write(*,"('  GetDeviceProperties for device ',i0,': Passed')") i+1
         Else
            Write(*,"('  GetDeviceProperties for device ',i0,': Failed')") i+1
         End If
         
!....    General device info

         Write(*,"('  Device Name: ',a)") trim(prop%name)
         Write(*,"('  Compute Capability: ',i0,'.',i0)") prop%major, prop%minor
         Write(*,"('  Number of Multiprocessors: ',i0)") prop%multiProcessorCount
         Write(*,"('  Max Threads per Multiprocessor: ',i0)") prop%maxThreadsPerMultiprocessor
         Write(*,"('  Global Memory (GB): ',f9.3,/)") prop%totalGlobalMem/1024.0**3
         
      End Do   
      
	  Return
      End Subroutine